import { _decorator, Component, Label,Animation } from "cc";
import { LanguageLabel } from "db://hiyooo-plugin-framework/libs/gui/language/LanguageLabel";

const {ccclass , property} = _decorator;

@ccclass("Notify")
export class Notify extends Component{
    @property(Label)
    private lab_content:Label = null!;
    @property(Animation)
    private animation:Animation = null!;

    /** 动画完成回调*/
    public onCompleted:Function = null!;

    protected onLoad(): void {
        if (this.animation) {
            this.animation.on(Animation.EventType.FINISHED,this.onAnimationFinished,this);
        }
    }

    /**
     * 动画完成回调
     */
    private onAnimationFinished():void{
        this.node.parent!.destroy();
        this.onCompleted && this.onCompleted();
        this.onCompleted = null;
    }

    /**
     * 显示Toast
     * @param conent 显示的文本
     * @param userI18n 多语言
     */
    public toast(content:string,userI18n:boolean){
        let label  = this.lab_content.getComponent(LanguageLabel!);
        if (userI18n) {
            label.enabled = true;
            label.dataID =content;
        }else{
            label.enabled = false;
            this.lab_content.string = content;
        }
    }

}